package mapper

import (
	"fmt"
	"github.com/beego/beego/v2/client/orm"
	"ksd-social-api/modules/special/model"
)

type AdminSpecialBindMapper struct {
}

/**
 * @author feige
 * @date 2023-10-10
 * @version 1.0
 * @desc  保存用户
 */
func (service *AdminSpecialBindMapper) SaveUpdateSpecialBind(specialBind model.SpecialBind) *model.SpecialBind {
	db := orm.NewOrm()
	if specialBind.Id > 0 {
		_, _ = db.Update(&specialBind)
		return &specialBind
	} else {
		_, _ = db.Insert(&specialBind)
		return &specialBind
	}
}

/**
 * @author feige
 * @date 2023-10-10
 * @version 1.0
 * @desc  根据用户id查询用户明细
 */
func (mapper *AdminSpecialBindMapper) UpdateFieldById(id uint64, field string, value any, systemId uint64) bool {
	// 创建orm对象
	mysql := orm.NewOrm()
	_, err := mysql.Raw(fmt.Sprintf("update xk_special_bind set %s='%v',update_time=now() where id = ? and system_id = ?", field, value)).SetArgs(id, systemId).Exec()
	if err != nil {
		return false
	}
	return true
}

/**
 * @author feige
 * @date 2023-10-10
 * @version 1.0
 * @desc  根据id删除
 */
func (mapper *AdminSpecialBindMapper) DelById(id uint64, systemId uint64) bool {
	// 创建orm对象
	mysql := orm.NewOrm()
	_, err := mysql.Raw("delete from xk_special_bind  where id = ? and system_id = ?").SetArgs(id, systemId).Exec()
	if err != nil {
		return false
	}
	return true
}
